package com.mud.mudcommune.view.fragment.threeLevel;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.mud.mudcommune.R;
import com.mud.mudcommune.utils.LogUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class WebViewFragment extends Fragment {
    private static final String TAG = WebViewFragment.class.getSimpleName();
    public static Fragment fragment = new WebViewFragment();
    @BindView(R.id.webView)
    WebView webView;
    private String vrUrl=null;

    public static Fragment getInstance() {
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle args = getArguments();
        if (args != null) {
            vrUrl = (String) args.get("vrUrl");
        }
        if(args!=null&&vrUrl==null){
            vrUrl = (String) args.get("Subject");
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_web_view, container, false);
        ButterKnife.bind(this, view);
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);//支持javascript
        LogUtils.i(TAG, vrUrl + "");
        webView.loadUrl(vrUrl);
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                //返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器
                view.loadUrl(url);//数据加载不出来
                return true;
            }
        });
        return view;
    }
}
